package com.demo2do.fms.admin.entity.search.supplier;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.appraisal.AppraisalType;

/**
 *
 * @author Ark
 *
 */
public class AppraisalResultSearch implements QueryBuilder {
    
    /** 接收考核供方 */
    private String target; 
    
    /** 考核名称 */
    private String appraisalName;
    
    /** 供方代码 */
    private String code;
    
    /** 供方名称 */
    private String name;
    
    /** 考核类型 */
    private AppraisalType appraisalType;
    
    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * The default constructor
     */
    public AppraisalResultSearch() {
        queryOrder = new QueryOrder("createTime", "DESC");
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("target", target)
                                           .addLike("appraisal.name", appraisalName)
                                           .addEquals("code", code)
                                           .addLike("name", name)
                                           .addEquals("appraisalType", appraisalType)
                                           .addEquals("disabled", false);
            
        }
        
        return queryFilter;
        
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM AppraisalResult" + getPreparedFilter(false).whereSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }

    /**
     * @return
     */
    public String getTarget() {
        return target;
    }
    
    /**
     * @return the appraisalName
     */
    public String getAppraisalName() {
        return appraisalName;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    
    /**
     * @return
     */
    public AppraisalType getAppraisalType() {
        return appraisalType;
    }

    /**
     * @param target
     */
    public void setTarget(String target) {
        this.target = target;
    }
    
    /**
     * @param appraisalName the appraisalName to set
     */
    public void setAppraisalName(String appraisalName) {
        this.appraisalName = appraisalName;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * @param appraisalType
     */
    public void setAppraisalType(AppraisalType appraisalType) {
        this.appraisalType = appraisalType;
    }
    
}